﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace Inspired.Euler
{
    public static class Problem056
    {
        /// <summary>
        /// Considering natural numbers of the form, <i>a<sup>b</sup></i>, finding the maximum digital sum.
        /// </summary>
        [EulerProblem(56, Title = "Considering natural numbers of the form, <i>a<sup>b</sup></i>, finding the maximum digital sum.")]
        public static long Solve()
        {
            return (long)
                Enumerable.Range(1, 99).SelectMany(a =>
                Enumerable.Range(1, 99), (a, b) =>
                    BigInteger.Pow(a, b).ToString()
                        .Select(c => Char.GetNumericValue(c))
                        .Sum())
                    .Max();
        }
    }
}
